<#include "/common/taglibs.ftl" />
<script>
    function notFoundData(id, dataType) {
        var tips = dataType + " [ID=" + id + "] " + '<@spring.message code="not.found"/>';
        return '<a class="btn m-btn btn-outline-danger btn-sm">' + tips + '</a>'
    }

    function label(data) {
        return '<a class="btn m-btn btn-outline-info btn-sm">' + data + '</a>'
    }

    function getExtraData(meta) {
        return $(meta.settings.nTable).data("extraData");
    }

    var renderRole = function (data, type, full, meta) {
        var html = [];
        var extraData = getExtraData(meta);
        $.each(full.roleIds.sort(), function (i, roleId) {
            var obj = extraData.roles[roleId];
            html.push(obj ? label(obj.name) : notFoundData(roleId, '<@spring.message code="role"/>'));
        });
        return html.join('<br/>');
    }

    var renderPermission = function (data, type, full, meta) {
        var html = [];
        var extraData = getExtraData(meta);
        $.each(full.permissionIds.sort(), function (i, permissionId) {
            var obj = extraData.permissions[permissionId];
            html.push(obj ? label(obj.name) : notFoundData(permissionId, '<@spring.message code="permission"/>'));
        });
        return html.join('<br/>');
    }

    var renderUser = function (data, type, full, meta) {
        var extraData = getExtraData(meta);
        var id = full.userId;
        var obj = extraData.users[id];
        return obj ? label(obj.name) : notFoundData(id, '<@spring.message code="user"/>');
    }

    var renderGroup = function (data, type, full, meta) {
        var extraData = getExtraData(meta);
        var id = full.groupId;
        var obj = extraData.groups[id];
        return obj ? label(obj.name) : notFoundData(id, '<@spring.message code="group"/>');
    }
</script>